Public Class FileForm

  Private Sub FileFromButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileFromButton.Click

    ChooseOpenFileDialog.Multiselect = False
    ChooseOpenFileDialog.ShowDialog()

    Me.FromTextBox.Text = ChooseOpenFileDialog.FileName

    If ToTextBox.Text.Length = 0 Then

      Me.ToTextBox.Text = My.Computer.FileSystem.CombinePath(System.IO.Path.GetTempPath, My.Computer.FileSystem.GetName(Me.FromTextBox.Text))

    End If

  End Sub

  Private Sub FileToButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToButton.Click

    Me.SaveFolderBrowserDialog.ShowDialog()

    Me.ToTextBox.Text = My.Computer.FileSystem.CombinePath(Me.SaveFolderBrowserDialog.SelectedPath, My.Computer.FileSystem.GetName(Me.FromTextBox.Text))

  End Sub

  Private Sub ReadTextWithProgressButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadTextWithProgressButton.Click

    OutputTextBox.Text = String.Empty

    If My.Computer.FileSystem.FileExists(Me.FromTextBox.Text) AndAlso System.IO.Path.GetExtension(Me.FromTextBox.Text) = ".txt" Then

      AddHandler dotNetTips.Utility.IO.FileHelper.ReadTextFileProgress, AddressOf Me.ReadTextFileProgress

      StatusProgressBar.Visible = True

      OutputTextBox.Text = dotNetTips.Utility.IO.FileHelper.ReadTextFile(FromTextBox.Text, System.Text.Encoding.ASCII)

    Else
      MessageBox.Show("File not found or extention is not txt")
    End If

  End Sub

  Private Sub ReadTextFileProgress(ByVal sender As Object, ByVal e As dotNetTips.Utility.IO.FileProcessEventArgs)

    StatusProgressBar.Value = CInt(e.Percent)

    If e.Percent = 100 Then

      RemoveHandler dotNetTips.Utility.IO.FileHelper.ReadTextFileProgress, AddressOf Me.ReadTextFileProgress

      StatusProgressBar.Value = 0
      StatusProgressBar.Visible = False

    End If

  End Sub

  Private Sub CopyFileWithDialogButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyFileWithDialogButton.Click

    OutputTextBox.Text = String.Empty

    If My.Computer.FileSystem.FileExists(Me.FromTextBox.Text) AndAlso System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(Me.ToTextBox.Text)) Then

      dotNetTips.Utility.IO.FileHelper.CopyFile(Me.FromTextBox.Text, Me.ToTextBox.Text, FileIO.UIOption.AllDialogs)

    Else
      MessageBox.Show("File or destination directory not correct.")
    End If

  End Sub

  Private Sub FindFileButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindFileButton.Click


    Dim file As String = dotNetTips.Utility.IO.PathHelper.FindPathOnDrives("c:\temp\application.myapp")

  End Sub

  Private Sub ConvertPathButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertPathButton.Click
    If FromTextBox.Text.Length > 0 Then
      OutputTextBox.Text = String.Empty

      OutputTextBox.Text = dotNetTips.Utility.IO.PathHelper.ConvertLongPathToShort(FromTextBox.Text)

    End If
  End Sub

  Private Sub SerialNumberButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SerialNumberButton.Click
    If FromTextBox.Text.Length > 0 Then
      OutputTextBox.Text = String.Empty

      OutputTextBox.Text = dotNetTips.Utility.IO.DriveHelper.GetDriveSerialNumber(My.Computer.FileSystem.GetDriveInfo(FromTextBox.Text).Name)

    End If
  End Sub
End Class